﻿using System;
using System.Collections;
using NUnit.Framework;
using Smartkernel;
using Smartkernel.Attributes;

namespace Smartkernel.NUnitTest.Attributes
{
    [Category("Attributes")]
    [TestFixture]
    public class SmartXmlMappingAttributeTest
    {
        [Test]
        public void Test()
        {
            //【01】测试两个特性是否相等（涉及方法：Equals）
            SmartXmlMappingAttribute attribute1 = new SmartXmlMappingAttribute("SQLCONN");
            SmartXmlMappingAttribute attribute2 = new SmartXmlMappingAttribute("SQLCONN");
            SmartXmlMappingAttribute attribute3 = new SmartXmlMappingAttribute("SQLCONN");
            attribute3.DefaultValue = @"Server=SmartKernel-PC\SQLSERVER2005;Database=Test;Uid=sa;Pwd=sa;";
            Assert.AreEqual(attribute1.Equals(attribute2), true);
            Assert.AreEqual(attribute1.Equals(attribute3), false);

            //【02】测试SmartXmlMappingAttribute类型作为键的情况（涉及方法：GetHashCode、Equals）
            Hashtable hashtable = new Hashtable();
            string ticks = DateTime.Now.Ticks.ToString();
            hashtable.Add(attribute1, ticks);
            Assert.AreEqual(hashtable[attribute2].ToString(), ticks);
            Assert.AreEqual(hashtable[attribute3], null);

            //【03】测试列名为空是引发异常（涉及方法：构造函数）
            Assert.AreEqual(SmartAction.IsInvokeFail(delegate { new SmartXmlMappingAttribute(" "); }), true);
            Assert.AreEqual(SmartAction.IsInvokeFail(delegate { new SmartXmlMappingAttribute(null); }), true);
        }
    }
}
